package com.xohm.daemon.tester;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import com.xohm.daemon.ClientHttpRequest;

@SuppressWarnings("all")
public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
	    try
	    {
	    	// Setup the session
			URL serverUrl = new URL("http://localhost:9824/wimax");
			URLConnection serverConnection = serverUrl.openConnection();

			// Inform the connection that we will send output and accept input
			// (doPost)
			serverConnection.setDoInput(true);
			serverConnection.setDoOutput(true);

			// Don't use a cached version of URL connection.
			serverConnection.setUseCaches(false);

			ClientHttpRequest httpRequest = new ClientHttpRequest(serverConnection);
			httpRequest.write(getTestXml());
			InputStream is = httpRequest.post();

			InputStreamReader in = new InputStreamReader(is);
			BufferedReader buf = new BufferedReader(in);
			String line = null;
			StringBuffer response = new StringBuffer(1000);
			while ((line = buf.readLine()) != null)
			{
				response.append(line);
			}
			System.out.println(response.toString());
	    }
	    catch (IOException e)
	    {
	      System.out.println("Exception: " + e.toString());
	    }
	}

	private static String getTestXml()
	{
		String xml = "";
		String controlNumber = "1226085623659";
		
		xml = "<WiMaxDaemon command=\"requestControl\"/>";
//		xml = "<WiMaxDaemon command=\"requestControl\"></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"requestControl\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"connect\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"connectionStatus\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"connectionStatus\"></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"connectionStatistics\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"linkStatus\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"registered\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"disconnect\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
//		xml = "<WiMaxDaemon command=\"kill\"><controlNumber>"+controlNumber+"</controlNumber></WiMaxDaemon>";
		
		return xml;
	}
}
